package com.ts.api.http.platform.biz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.algorithm.encrypt.symmetric.AES;
import com.gitee.apanlh.util.base.ChooseEq;
import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.base.IteratorUtils;
import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.common.util.ApiDictUtils;
import com.ts.api.http.platform.entity.apply.ApiPlatApplyXiaoYuan;
import com.ts.api.http.platform.entity.dataexchange.ApiPlatDataExchangeXiaoYuan;
import com.ts.api.module.api.convert.core.annotation.ApiPlan;
import com.ts.api.module.api.convert.core.annotation.ApiPlanConvertType;
import com.ts.api.module.api.convert.core.entity.ApiApplyParameter;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.core.entity.ApiDataExchangeParameter;
import com.ts.api.module.api.convert.platform.entity.RespPlatformMultiPhoneMaskDataExchange;
import com.ts.api.module.api.convert.platform.entity.RespPlatformNoticeApply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMaskApply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMaskDataExchange;
import com.ts.api.module.api.convert.platform.handler.ApiPlatformPhoneMaskConvertHandler;
import com.ts.api.module.api.entity.ApiProtocol;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 李源聪
 * 2025年06月20日 10:31
 */
@ApiPlan(productId = "1000074", type = ApiPlanConvertType.PLAT_PHONE_MASK)
public class ApiPlatYuanRongHuaMaskConvert implements ApiPlatformPhoneMaskConvertHandler {

    private static final String KEY = "CB613DE5A22EDBA9";
    private static final String ACCOUNT_NO = "20231983";

    @Override
    public RespPlatformNoticeApply parseApplyNotice(RequestVO requestVO) {
        JSONObject jsonObject = JsonUtils.get(requestVO.getBody());
        String data = jsonObject.getString("data");

        RespPlatformNoticeApply applyNotice = new RespPlatformNoticeApply();
        AES aes = AES.createEcb(KEY.getBytes());
        String dataStr = aes.encryptToBase64Str(JsonUtils.toJson(data));
        JSONObject dataJsonObject = JsonUtils.get(dataStr);
        String serialNo = dataJsonObject.getString("serialNo");
        applyNotice.setApplyId(serialNo);
        return applyNotice;
    }

    @Override
    public Map<String, Object> respApplyNotice(ApiBizStatus apiBizStatusMessage) {
        boolean b = apiBizStatusMessage.hasBizSuc();

        if (b) {
            return MapUtils.newHashMap(newHashMap -> {
                newHashMap.put("code", 200);
                newHashMap.put("msg", "操作成功");
            });
        }
        return MapUtils.newHashMap(newHashMap -> {
            newHashMap.put("code", 500);
            newHashMap.put("msg", "操作失败");
        });
    }

    @Override
    public Object dataExchange(ApiDataExchangeParameter apiDataChangeMessage) throws Exception {
        ApiPlatDataExchangeXiaoYuan data = new ApiPlatDataExchangeXiaoYuan();

        data.setVersion("1.0.0");

        data.setSerialNo(apiDataChangeMessage.getReqId());

        data.setTimestamp(String.valueOf(System.currentTimeMillis()));

        ApiPlatDataExchangeXiaoYuan.FieldInfo fieldInfo = new ApiPlatDataExchangeXiaoYuan.FieldInfo();

        data.setPhoneMask(apiDataChangeMessage.getPhoneMask());

        data.setUserName("浩安星");

        //  年龄(21岁-55岁)
        String age = ApiDictUtils.convertAge(apiDataChangeMessage.getAge());
        data.setAge(age);

        // loadAmount 用户借款额度 值可能 (1：0-3万 2：3-5万 3：5-10万 4：10-20万 5：20万以上)
        // loanAmount 贷款金额
        // 1 3万以下
        // 2 5万-10万
        // 3 10万-20万
        // 4 20万以上
        String loanAmount = apiDataChangeMessage.getLoanAmount();
        if (ValidParam.isNotEmpty(loanAmount)) {
            String value = ChooseEq.create()
                    .when(loanAmount, "1", "1")
                    .when(loanAmount, "2", "1")
                    .when(loanAmount, "3", "2")
                    .when(loanAmount, "4", "3")
                    .when(loanAmount, "5", "4")
                    .end("1");
            fieldInfo.setLoanAmount(value);
        }

        // zhima 芝麻分 值可能 (1：600分以下 2：600-650分 3：650-700分 4：700分以上
        // sesameCredit 芝麻分
        // 1 600分以下
        // 2 600~649分
        // 3 650~699分
        // 4 700分以上
        String sesameCredit = apiDataChangeMessage.getSesameCredit();
        if (ValidParam.isNotEmpty(sesameCredit)) {
            String value = ChooseEq.create()
                    .when(sesameCredit, "1", "1")
                    .when(sesameCredit, "2", "2")
                    .when(sesameCredit, "3", "3")
                    .when(sesameCredit, "4", "4")
                    .end();
            fieldInfo.setSesameCredit(value);
        }

        // house 房 值可能 (1：无房 2：有房可抵押 3：有房不抵押)
        // realEstateInfo 房产情况
        // 1 无房产
        // 2 有房不抵押
        // 3 有房可抵押
        // 4 有房产
        // 5 有按揭房产
        // 6 有全款房产
        String realEstateInfo = apiDataChangeMessage.getRealEstateInfo();
        if (ValidParam.isNotEmpty(realEstateInfo)) {
            String value = ChooseEq.create()
                    .when(realEstateInfo, "1", "1")
                    .when(realEstateInfo, "2", "3")
                    .when(realEstateInfo, "3", "2")
                    .when(realEstateInfo, "4", "2")
                    .when(realEstateInfo, "5", "2")
                    .when(realEstateInfo, "6", "2")
                    .end();
            fieldInfo.setRealEstateInfo(value);
        }

        // car 车 值可能 (1：无车 2：有车可抵押 3：有车不抵押)
        // carInfo 车辆情况
        // 1 无车产
        // 2 有车不抵押
        // 3 有车可抵押
        // 4 有车产
        String carInfo = apiDataChangeMessage.getCarInfo();
        if (ValidParam.isNotEmpty(carInfo)) {
            String value = ChooseEq.create()
                    .when(carInfo, "1", "1")
                    .when(carInfo, "2", "3")
                    .when(carInfo, "3", "2")
                    .when(carInfo, "4", "2")
                    .end();
            fieldInfo.setCarInfo(value);
        }


        // pubFund 公积金 值可能 (1：无公积金 2：缴纳一年以上 3：缴纳一年以下)
        // providentFund 公积金
        // 1 无公积金
        // 2 缴纳6个月以下
        // 3 缴纳6个月以上
        // 4 有公积金
        String providentFund = apiDataChangeMessage.getProvidentFund();
        if (ValidParam.isNotEmpty(providentFund)) {
            String value = ChooseEq.create()
                    .when(providentFund, "1", "1")
                    .when(providentFund, "2", "3")
                    .when(providentFund, "3", "2")
                    .when(providentFund, "4", "3")
                    .end();
            fieldInfo.setProvidentFund(value);
        }

        // guarantor 保单 值可能 (1：无保单 2：缴纳一年以上 3：缴纳一年以下)
        // insurancePolicy 保险保单
        // 1 无保险保单
        // 2 缴纳未满1年
        // 3 缴纳1年以上
        // 4 有保险保单
        String insurancePolicy = apiDataChangeMessage.getInsurancePolicy();
        if (ValidParam.isNotEmpty(insurancePolicy)) {
            String value = ChooseEq.create()
                    .when(insurancePolicy, "1", "1")
                    .when(insurancePolicy, "2", "3")
                    .when(insurancePolicy, "3", "2")
                    .when(insurancePolicy, "4", "2")
                    .end();
            fieldInfo.setInsurancePolicy(value);
        }

        // creditRecord 信用记录 值可能 (1：无信用记录 2：信用良好无逾期 3：一年内有30天以上逾期 4：一年内无30天以上逾期)
        // overdue 逾期
        // 1 无逾期
        // 2 当前有逾期
        // 3 一年以内无逾期
        String overdue = apiDataChangeMessage.getOverdue();
        if (ValidParam.isNotEmpty(overdue)) {
            String value = ChooseEq.create()
                    .when(overdue, "1", "1")
                    .when(overdue, "2", "4")
                    .when(overdue, "3", "3")
                    .end();
            fieldInfo.setOverdue(value);
        }

        // creditCard 信用卡 值可能 (1：无信用卡 2：有信用卡)
        // creditLimit 信用卡额度
        // 1 无信用卡
        // 2 3千以下
        // 3 3千-1万
        // 4 1-3万
        // 5 3万以上
        // 6 有信用卡
        String creditLimit = apiDataChangeMessage.getCreditLimit();
        if (ValidParam.isNotEmpty(creditLimit)) {
            String value = ChooseEq.create()
                    .when(creditLimit, "1", "1")
                    .when(creditLimit, "2", "2")
                    .when(creditLimit, "3", "2")
                    .when(creditLimit, "4", "2")
                    .when(creditLimit, "5", "2")
                    .when(creditLimit, "6", "2")
                    .end();
            fieldInfo.setCreditLimit(value);
        }

        // socialSecurity 社保 值可能 (1：无社保 2：缴纳半年以上 3：缴纳半年以下)
        // socialSecurity 社保缴纳
        // 1 无社保
        // 2 缴纳6个月以下
        // 3 缴纳6个月以上
        // 4 有社保
        String socialSecurity = apiDataChangeMessage.getSocialSecurity();
        if (ValidParam.isNotEmpty(socialSecurity)) {
            String value = ChooseEq.create()
                    .when(socialSecurity, "1", "1")
                    .when(socialSecurity, "2", "3")
                    .when(socialSecurity, "3", "2")
                    .end();
            fieldInfo.setSocialSecurity(value);
        }

        // baitiao 京东白条 值可能 (1：无白条 2：3000以下 3：3000-10000 4：10000以上)
        // btLimit 京东白条可用额度
        // 1 无额度
        // 2 3千以下
        // 3 3千-1万
        // 4 1-3万
        // 5 3万以上
        String btLimit = apiDataChangeMessage.getBtLimit();
        if (ValidParam.isNotEmpty(btLimit)) {
            String value = ChooseEq.create()
                    .when(btLimit, "1", "1")
                    .when(btLimit, "2", "2")
                    .when(btLimit, "3", "3")
                    .when(btLimit, "4", "4")
                    .when(btLimit, "5", "4")
                    .end();
            fieldInfo.setBtLimit(value);
        }

        // work 职业 值可能 (1：上班族 2：企业主 3：个体户 4：自由职业)
        // career
        //   1	上班族
        //   2	自由职业
        //   3	企业主（有营业执照）
        //   4	公务员或事业单位
        //   5	个体户
        String career = apiDataChangeMessage.getCareer();
        if (ValidParam.isNotEmpty(career)) {
            String value = ChooseEq.create()
                    .when(career, "1", "1")
                    .when(career, "2", "4")
                    .when(career, "3", "2")
                    .when(career, "4", "3")
                    .when(career, "5", "3")
                    .end();
            fieldInfo.setCareer(value);
        }

        // purpose 贷款用途 值可能 (1：日常消费 2：装修 3：旅游 4：教育培训 5：婚庆)
        // loanPurpose
        // 1 旅游
        // 2 教育
        // 3 婚庆
        // 4 装修
        // 5 医疗
        // 6 个人消费
        String loanPurpose = apiDataChangeMessage.getLoanPurpose();
        if (ValidParam.isNotEmpty(loanPurpose)) {
            String value = ChooseEq.create()
                    .when(loanPurpose, "1", "6")
                    .when(loanPurpose, "2", "4")
                    .when(loanPurpose, "3", "5")
                    .when(loanPurpose, "4", "1")
                    .when(loanPurpose, "5", "1")
                    .when(loanPurpose, "6", "1")
                    .end();
            fieldInfo.setLoanPurpose(value);
        }

        // salarySettleType 收入情况 值可能 (1：现金收入 2：打卡工资 )
        // salaryPayMethod
        // 1 银行代发打卡
        // 2 现金收入
        // 3 个人转账
        String salaryPayMethod = apiDataChangeMessage.getSalaryPayMethod();
        if (ValidParam.isNotEmpty(salaryPayMethod)) {
            String value = ChooseEq.create()
                    .when(salaryPayMethod, "1", "2")
                    .when(salaryPayMethod, "2", "1")
                    .when(salaryPayMethod, "3", "2")
                    .end();
            fieldInfo.setSalaryPayMethod(value);
        }

        // education 学历 值可能 (1：高中及以下 2：大专 3：本科及以上)
        // educationAttainment 学历
        // 1 初中及以下
        // 2 中专
        // 3 高中
        // 4 大专
        // 5 本科
        // 6 研究生及以上
        String educationAttainment = apiDataChangeMessage.getEducationAttainment();
        if (ValidParam.isNotEmpty(educationAttainment)) {
            String value = ChooseEq.create()
                    .when(educationAttainment, "1", "1")
                    .when(educationAttainment, "2", "1")
                    .when(educationAttainment, "3", "1")
                    .when(educationAttainment, "4", "2")
                    .when(educationAttainment, "5", "3")
                    .when(educationAttainment, "6", "3")
                    .end();
            fieldInfo.setEducationAttainment(value);
        }

        // monthIncome 月收入(元) 例：5500，没有默认传5500
        String monthlySalary = apiDataChangeMessage.getMonthlySalary();
        if (ValidParam.isNotEmpty(monthlySalary)) {
            String value = ChooseEq.create()
                    .when(monthlySalary, "1", "1000")
                    .when(monthlySalary, "2", "3000")
                    .when(monthlySalary, "3", "8000")
                    .when(monthlySalary, "4", "15000")
                    .when(monthlySalary, "5", "30000")
                    .end();

            fieldInfo.setMonthlySalary(value);
        }
        AES aes = AES.createEcb(KEY.getBytes());
        String dataStr = aes.encryptToBase64Str(JsonUtils.toJson(data));
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("accountNo", ACCOUNT_NO);
            newMap.put("data", dataStr);
        });
        return JsonUtils.toJson(map);
    }

    @Override
    public RespPlatformMultiPhoneMaskDataExchange respDataExchange(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }
        if (!Eq.object(jsonObject.getInteger("code"), 200)) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }
        JSONArray resData = JsonUtils.get(respJson).getJSONArray("data");
        if (ValidParam.isEmpty(resData)) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }

        RespPlatformMultiPhoneMaskDataExchange respPlatformMultiPhoneMaskDataExchange = RespPlatformMultiPhoneMaskDataExchange.ofSuc();
        List<RespPlatformPhoneMaskDataExchange> listRespPlatformPhoneMaskDataExchange = CollUtils.newArrayList();

        for (int i = 0; i < resData.size(); i++) {
            JSONObject item = resData.getJSONObject(i);
            if (ValidParam.isNotNull(item)) {
                BigDecimal price = item.getBigDecimal("sysSellMoney");
                String companyName = item.getString("companyName");
                String productName = item.getString("productName");
                String logo = item.getString("logoUrl");
                String orderId = item.getString("orderId");

                List<ApiProtocol> protocolList = CollUtils.newArrayList(newList -> {
                    //  获取协议
                    JSONArray listProtocolResult = item.getJSONArray("authList");
                    IteratorUtils.array(listProtocolResult, (protocolResult, index) -> {
                        JSONObject protocolObject = listProtocolResult.getJSONObject(index);
                        ApiProtocol protocol = new ApiProtocol();
                        protocol.setProtocolName(protocolObject.getString("authName"));
                        protocol.setProtocolUrl(protocolObject.getString("authUrl"));
                        newList.add(protocol);
                    });
                });

                List<String> phoneMd5List = CollUtils.newArrayList(newList -> {
                    JSONArray jsonArray = item.getJSONArray("phoneMd5List");
                    IteratorUtils.array(jsonArray, (protocolResult, index) -> {
                        String phoneMd5 = jsonArray.getString(index);
                        newList.add(phoneMd5);
                    });
                });
                RespPlatformPhoneMaskDataExchange result = RespPlatformPhoneMaskDataExchange.of();

                result.setPrice(price);
                result.setLogoPath(logo);
                result.setDisplayName(companyName);
                result.setProductName(productName);
                result.setApplyId(orderId);
                result.setProtocolList(protocolList);
                result.setListPhoneMd5(phoneMd5List);
                listRespPlatformPhoneMaskDataExchange.add(result);
            }
        }
        respPlatformMultiPhoneMaskDataExchange.setListPhoneMask(listRespPlatformPhoneMaskDataExchange);
        return respPlatformMultiPhoneMaskDataExchange;
    }

    @Override
    public Object apply(ApiApplyParameter apiApplyMessage) throws Exception {
        ApiPlatApplyXiaoYuan data = new ApiPlatApplyXiaoYuan();

        data.setVersion("1.0.0");

        data.setSerialNo(apiApplyMessage.getReqId());

        data.setTimestamp(String.valueOf(System.currentTimeMillis()));

        ApiPlatDataExchangeXiaoYuan.FieldInfo fieldInfo = new ApiPlatDataExchangeXiaoYuan.FieldInfo();

        data.setPhone(apiApplyMessage.getPhone());

        data.setUserName(apiApplyMessage.getUserName());

        //  年龄(21岁-55岁)
        String age = ApiDictUtils.convertAge(apiApplyMessage.getAge());
        data.setAge(age);

        // loadAmount 用户借款额度 值可能 (1：0-3万 2：3-5万 3：5-10万 4：10-20万 5：20万以上)
        // loanAmount 贷款金额
        // 1 3万以下
        // 2 5万-10万
        // 3 10万-20万
        // 4 20万以上
        String loanAmount = apiApplyMessage.getLoanAmount();
        if (ValidParam.isNotEmpty(loanAmount)) {
            String value = ChooseEq.create()
                    .when(loanAmount, "1", "1")
                    .when(loanAmount, "2", "1")
                    .when(loanAmount, "3", "2")
                    .when(loanAmount, "4", "3")
                    .when(loanAmount, "5", "4")
                    .end("1");
            fieldInfo.setLoanAmount(value);
        }

        // zhima 芝麻分 值可能 (1：600分以下 2：600-650分 3：650-700分 4：700分以上
        // sesameCredit 芝麻分
        // 1 600分以下
        // 2 600~649分
        // 3 650~699分
        // 4 700分以上
        String sesameCredit = apiApplyMessage.getSesameCredit();
        if (ValidParam.isNotEmpty(sesameCredit)) {
            String value = ChooseEq.create()
                    .when(sesameCredit, "1", "1")
                    .when(sesameCredit, "2", "2")
                    .when(sesameCredit, "3", "3")
                    .when(sesameCredit, "4", "4")
                    .end();
            fieldInfo.setSesameCredit(value);
        }

        // house 房 值可能 (1：无房 2：有房可抵押 3：有房不抵押)
        // realEstateInfo 房产情况
        // 1 无房产
        // 2 有房不抵押
        // 3 有房可抵押
        // 4 有房产
        // 5 有按揭房产
        // 6 有全款房产
        String realEstateInfo = apiApplyMessage.getRealEstateInfo();
        if (ValidParam.isNotEmpty(realEstateInfo)) {
            String value = ChooseEq.create()
                    .when(realEstateInfo, "1", "1")
                    .when(realEstateInfo, "2", "3")
                    .when(realEstateInfo, "3", "2")
                    .when(realEstateInfo, "4", "2")
                    .when(realEstateInfo, "5", "2")
                    .when(realEstateInfo, "6", "2")
                    .end();
            fieldInfo.setRealEstateInfo(value);
        }

        // car 车 值可能 (1：无车 2：有车可抵押 3：有车不抵押)
        // carInfo 车辆情况
        // 1 无车产
        // 2 有车不抵押
        // 3 有车可抵押
        // 4 有车产
        String carInfo = apiApplyMessage.getCarInfo();
        if (ValidParam.isNotEmpty(carInfo)) {
            String value = ChooseEq.create()
                    .when(carInfo, "1", "1")
                    .when(carInfo, "2", "3")
                    .when(carInfo, "3", "2")
                    .when(carInfo, "4", "2")
                    .end();
            fieldInfo.setCarInfo(value);
        }


        // pubFund 公积金 值可能 (1：无公积金 2：缴纳一年以上 3：缴纳一年以下)
        // providentFund 公积金
        // 1 无公积金
        // 2 缴纳6个月以下
        // 3 缴纳6个月以上
        // 4 有公积金
        String providentFund = apiApplyMessage.getProvidentFund();
        if (ValidParam.isNotEmpty(providentFund)) {
            String value = ChooseEq.create()
                    .when(providentFund, "1", "1")
                    .when(providentFund, "2", "3")
                    .when(providentFund, "3", "2")
                    .when(providentFund, "4", "3")
                    .end();
            fieldInfo.setProvidentFund(value);
        }

        // guarantor 保单 值可能 (1：无保单 2：缴纳一年以上 3：缴纳一年以下)
        // insurancePolicy 保险保单
        // 1 无保险保单
        // 2 缴纳未满1年
        // 3 缴纳1年以上
        // 4 有保险保单
        String insurancePolicy = apiApplyMessage.getInsurancePolicy();
        if (ValidParam.isNotEmpty(insurancePolicy)) {
            String value = ChooseEq.create()
                    .when(insurancePolicy, "1", "1")
                    .when(insurancePolicy, "2", "3")
                    .when(insurancePolicy, "3", "2")
                    .when(insurancePolicy, "4", "2")
                    .end();
            fieldInfo.setInsurancePolicy(value);
        }

        // creditRecord 信用记录 值可能 (1：无信用记录 2：信用良好无逾期 3：一年内有30天以上逾期 4：一年内无30天以上逾期)
        // overdue 逾期
        // 1 无逾期
        // 2 当前有逾期
        // 3 一年以内无逾期
        String overdue = apiApplyMessage.getOverdue();
        if (ValidParam.isNotEmpty(overdue)) {
            String value = ChooseEq.create()
                    .when(overdue, "1", "1")
                    .when(overdue, "2", "4")
                    .when(overdue, "3", "3")
                    .end();
            fieldInfo.setOverdue(value);
        }

        // creditCard 信用卡 值可能 (1：无信用卡 2：有信用卡)
        // creditLimit 信用卡额度
        // 1 无信用卡
        // 2 3千以下
        // 3 3千-1万
        // 4 1-3万
        // 5 3万以上
        // 6 有信用卡
        String creditLimit = apiApplyMessage.getCreditLimit();
        if (ValidParam.isNotEmpty(creditLimit)) {
            String value = ChooseEq.create()
                    .when(creditLimit, "1", "1")
                    .when(creditLimit, "2", "2")
                    .when(creditLimit, "3", "2")
                    .when(creditLimit, "4", "2")
                    .when(creditLimit, "5", "2")
                    .when(creditLimit, "6", "2")
                    .end();
            fieldInfo.setCreditLimit(value);
        }

        // socialSecurity 社保 值可能 (1：无社保 2：缴纳半年以上 3：缴纳半年以下)
        // socialSecurity 社保缴纳
        // 1 无社保
        // 2 缴纳6个月以下
        // 3 缴纳6个月以上
        // 4 有社保
        String socialSecurity = apiApplyMessage.getSocialSecurity();
        if (ValidParam.isNotEmpty(socialSecurity)) {
            String value = ChooseEq.create()
                    .when(socialSecurity, "1", "1")
                    .when(socialSecurity, "2", "3")
                    .when(socialSecurity, "3", "2")
                    .end();
            fieldInfo.setSocialSecurity(value);
        }

        // baitiao 京东白条 值可能 (1：无白条 2：3000以下 3：3000-10000 4：10000以上)
        // btLimit 京东白条可用额度
        // 1 无额度
        // 2 3千以下
        // 3 3千-1万
        // 4 1-3万
        // 5 3万以上
        String btLimit = apiApplyMessage.getBtLimit();
        if (ValidParam.isNotEmpty(btLimit)) {
            String value = ChooseEq.create()
                    .when(btLimit, "1", "1")
                    .when(btLimit, "2", "2")
                    .when(btLimit, "3", "3")
                    .when(btLimit, "4", "4")
                    .when(btLimit, "5", "4")
                    .end();
            fieldInfo.setBtLimit(value);
        }

        // work 职业 值可能 (1：上班族 2：企业主 3：个体户 4：自由职业)
        // career
        //   1	上班族
        //   2	自由职业
        //   3	企业主（有营业执照）
        //   4	公务员或事业单位
        //   5	个体户
        String career = apiApplyMessage.getCareer();
        if (ValidParam.isNotEmpty(career)) {
            String value = ChooseEq.create()
                    .when(career, "1", "1")
                    .when(career, "2", "4")
                    .when(career, "3", "2")
                    .when(career, "4", "3")
                    .when(career, "5", "3")
                    .end();
            fieldInfo.setCareer(value);
        }

        // purpose 贷款用途 值可能 (1：日常消费 2：装修 3：旅游 4：教育培训 5：婚庆)
        // loanPurpose
        // 1 旅游
        // 2 教育
        // 3 婚庆
        // 4 装修
        // 5 医疗
        // 6 个人消费
        String loanPurpose = apiApplyMessage.getLoanPurpose();
        if (ValidParam.isNotEmpty(loanPurpose)) {
            String value = ChooseEq.create()
                    .when(loanPurpose, "1", "6")
                    .when(loanPurpose, "2", "4")
                    .when(loanPurpose, "3", "5")
                    .when(loanPurpose, "4", "1")
                    .when(loanPurpose, "5", "1")
                    .when(loanPurpose, "6", "1")
                    .end();
            fieldInfo.setLoanPurpose(value);
        }

        // salarySettleType 收入情况 值可能 (1：现金收入 2：打卡工资 )
        // salaryPayMethod
        // 1 银行代发打卡
        // 2 现金收入
        // 3 个人转账
        String salaryPayMethod = apiApplyMessage.getSalaryPayMethod();
        if (ValidParam.isNotEmpty(salaryPayMethod)) {
            String value = ChooseEq.create()
                    .when(salaryPayMethod, "1", "2")
                    .when(salaryPayMethod, "2", "1")
                    .when(salaryPayMethod, "3", "2")
                    .end();
            fieldInfo.setSalaryPayMethod(value);
        }

        // education 学历 值可能 (1：高中及以下 2：大专 3：本科及以上)
        // educationAttainment 学历
        // 1 初中及以下
        // 2 中专
        // 3 高中
        // 4 大专
        // 5 本科
        // 6 研究生及以上
        String educationAttainment = apiApplyMessage.getEducationAttainment();
        if (ValidParam.isNotEmpty(educationAttainment)) {
            String value = ChooseEq.create()
                    .when(educationAttainment, "1", "1")
                    .when(educationAttainment, "2", "1")
                    .when(educationAttainment, "3", "1")
                    .when(educationAttainment, "4", "2")
                    .when(educationAttainment, "5", "3")
                    .when(educationAttainment, "6", "3")
                    .end();
            fieldInfo.setEducationAttainment(value);
        }

        // monthIncome 月收入(元) 例：5500，没有默认传5500
        String monthlySalary = apiApplyMessage.getMonthlySalary();
        if (ValidParam.isNotEmpty(monthlySalary)) {
            String value = ChooseEq.create()
                    .when(monthlySalary, "1", "1000")
                    .when(monthlySalary, "2", "3000")
                    .when(monthlySalary, "3", "8000")
                    .when(monthlySalary, "4", "15000")
                    .when(monthlySalary, "5", "30000")
                    .end();

            fieldInfo.setMonthlySalary(value);
        }
        AES aes = AES.createEcb(KEY.getBytes());
        String dataStr = aes.encryptToBase64Str(JsonUtils.toJson(data));
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("accountNo", ACCOUNT_NO);
            newMap.put("data", dataStr);
        });
        return JsonUtils.toJson(map);
    }
    @Override
    public RespPlatformPhoneMaskApply respApply(String respJson) throws Exception {
        //  进件返回响应体判断
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMaskApply.ofFail();
        }
        if (!Eq.object(jsonObject.getInteger("code"), 200)) {
            return RespPlatformPhoneMaskApply.ofFail();
        }
        return RespPlatformPhoneMaskApply.ofSuc();
    }
}
